package org.example.campsys.controller;

import org.example.campsys.model.*;
import org.example.campsys.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    public AdminService adminService;
    @RequestMapping("/countstudent")
    public Result countStudent(Integer status){
        return Result.success("查询成功",adminService.countStudent(status));
    }

    @RequestMapping("/countcourse")
    public Result countCourse(Integer status){
        return Result.success("查询成功",adminService.countCourse(status));
    }

    @RequestMapping("/countactivity")
    public Result countActivity(Integer status){
        return Result.success("查询成功",adminService.countActivity(status));
    }

    @RequestMapping("/addactivity")//新建活动
    public Result addActivity(@RequestBody ActivityInfo activityInfo){
        if (StringUtils.hasLength(activityInfo.getName()) && StringUtils.hasLength(activityInfo.getCategory()) &&
             StringUtils.hasLength(activityInfo.getCreator()) ){

            adminService.addActivity(activityInfo);
            return Result.success("成功添加",true);
        }
        return Result.fail("必选信息为空",false);
    }

    @RequestMapping("/addclass")//新建教学班
    public Result addClass(@RequestBody ClassInfo classInfo){
        if (StringUtils.hasLength(classInfo.getName())  && classInfo.getActivityId() != null){
             adminService.addClass(classInfo);
             return Result.success("成功添加", true);
        }
        return Result.fail("必选信息为空", false);
    }

    @RequestMapping("/selactivity")
    public Result selectActivity(@RequestBody ActivityInfo activityInfo){
        return Result.success("查询成功",adminService.selectActivity(activityInfo));
    }

    @RequestMapping("/delactivity")
    public Result deleteActivity(Integer id){
        adminService.deleteActivity(id);
        return Result.success("删除成功",true);
    }

    @RequestMapping("/updactivity")
    public Result updateActivity(@RequestBody ActivityInfo activityInfo){
        adminService.updateActivity(activityInfo);
         return Result.success("修改成功",true);
    }

    @RequestMapping("/orcactivity")
    public Result orcActivity(@RequestBody ActivityInfo activityInfo){
        adminService.orcActivity(activityInfo);
        return Result.success("开放或关闭成功",true);
    }

    @RequestMapping("/selclass")
    public Result selectClass(){
        return Result.success("查询成功",adminService.selectClass());
    }

    @RequestMapping("/cfgactivity")
    public Result cfgActivity(Integer activityId, Integer id){
        adminService.cfgClass(activityId,id);
        return Result.success("关联活动成功",true);
    }

    @RequestMapping("/cfgteacher")
    public Result cfgTeacher(Integer teahcerId, Integer id){
        adminService.cfgTeacher(teahcerId,id);
        return Result.success("关联教师成功",true);
    }

    @RequestMapping("/updclass")
    public Result updClass(@RequestBody ClassInfo classInfo){
        adminService.updClass(classInfo);
        return Result.success("修改成功",true);
    }

    @RequestMapping("/delclass")
    public Result deleteClass(Integer id){
        adminService.deleteClass(id);
        return Result.success("删除成功",true);
    }

    @RequestMapping("/selstudent")
    public Result selectStudent(@RequestBody StudentInfo studentInfo){
        return Result.success("查询成功",adminService.selectStudent(studentInfo));
    }

    @RequestMapping("/cfgstudent")
    public Result cfgStudent(Integer classId, Integer studentId){
        adminService.cfgStudent(classId,studentId);
        return Result.success("导入学生成功",true);
    }

    @RequestMapping("/updstudent")
    public Result updStudent(@RequestBody StudentInfo studentInfo){
        adminService.updStudent(studentInfo);
        return Result.success("修改学生成功",true);
    }

    @RequestMapping("/delstudent")
    public Result delStudent(Integer id){
        adminService.deleteStudent(id);
        return Result.success("删除学生成功", true);
    }

    @RequestMapping("/addstudent")
    public Result addStudent(@RequestBody StudentInfo studentInfo){
        if (StringUtils.hasLength(studentInfo.getStuName()) &&
            StringUtils.hasLength(studentInfo.getFromPlace()) &&
            StringUtils.hasLength(studentInfo.getParentPhone()) &&
            StringUtils.hasLength(studentInfo.getCurrentGrade()) &&
            StringUtils.hasLength(studentInfo.getIsFirst())){
            adminService.addStudent(studentInfo);
            return Result.success("添加学生成功", true);
        }
        return Result.fail("有必选项为空",false);
    }

    @RequestMapping("/audstudent")
    public Result auditStudent(@RequestBody StudentInfo studentInfo){
         adminService.auditStudent(studentInfo);
        return Result.success("审核成功", true);
    }

    @RequestMapping("/addteacher")
    public Result addTeacher(@RequestBody TeacherInfo teacherInfo){
        if(StringUtils.hasLength(teacherInfo.getTeacherName())){
            adminService.addTeacher(teacherInfo);
            return Result.success("添加教师成功",true);
        }
        return Result.fail("教师姓名不能为空",false);
    }

    @RequestMapping("/updteacher")
    public Result updteacher(@RequestBody TeacherInfo teacherInfo){
        if(StringUtils.hasLength(teacherInfo.getTeacherName())){
            adminService.updTeacher(teacherInfo);
            return Result.success("修改教师成功",true);
        }
        return Result.fail("教师姓名不能为空",false);
    }

    @RequestMapping("/selteacher")
    public Result selectTeacher(@RequestBody TeacherInfo teacherInfo){
        return Result.success("查询教师成功",adminService.selectTeacher(teacherInfo));
    }

    @RequestMapping("/delteacher")
    public Result delTeacher(Integer id){
        adminService.delTeacher(id);
        return Result.success("删除成功",true);
    }
    @RequestMapping("/selclassstudent")
    public Result selClassStu(Integer classId){
        return Result.success("查询成功", adminService.selClassStu(classId));
    }
}
